package cn.ad.server.web.spring.service.components.http.client;

import java.util.Map;

/**
 * http请求
 * @author wangwei
 *
 */
public class AdHttpRequest {
	
	long requstTime = System.currentTimeMillis();
	/**
	 * 请求url
	 */
	String url;
	
	Map<String, Object> params;
	
	Map<String, Object> headerParams;
	
	private RequestConfig config; 
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Map<String, Object> getParams() {
		return params;
	}

	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

	public long getRequstTime() {
		return requstTime;
	}

	public void setRequstTime(long requstTime) {
		this.requstTime = requstTime;
	}
	
	public RequestConfig getConfig() {
		return config;
	}

	public void setConfig(RequestConfig config) {
		this.config = config;
	}
	
	public void setTimeOut(int timeOut) {
		if(config==null){
			config = new RequestConfig();
		}
		config.setSocketTimeout(timeOut);
	}
	
	public int getTimeOut() {
		
		if(config==null){
			return -1;
		}
		return config.getSocketTimeout();
	}

	public Map<String, Object> getHeaderParams() {
		return headerParams;
	}

	public void setHeaderParams(Map<String, Object> headerParams) {
		this.headerParams = headerParams;
	}

	
	/**
	 * 请求config
	 * @author wangwei
	 *
	 */
	class RequestConfig{
		
		private int maxTotal=-1;

		private int defaultMaxPerRoute=-1;

		private int connectTimeout=-1;

		private int connectionRequestTimeout=-1;

		private int socketTimeout=-1;

		private boolean staleConnectionCheckEnabled;

		public int getMaxTotal() {
			return maxTotal;
		}

		public void setMaxTotal(int maxTotal) {
			this.maxTotal = maxTotal;
		}

		public int getDefaultMaxPerRoute() {
			return defaultMaxPerRoute;
		}

		public void setDefaultMaxPerRoute(int defaultMaxPerRoute) {
			this.defaultMaxPerRoute = defaultMaxPerRoute;
		}

		public int getConnectTimeout() {
			return connectTimeout;
		}

		public void setConnectTimeout(int connectTimeout) {
			this.connectTimeout = connectTimeout;
		}

		public int getConnectionRequestTimeout() {
			return connectionRequestTimeout;
		}

		public void setConnectionRequestTimeout(int connectionRequestTimeout) {
			this.connectionRequestTimeout = connectionRequestTimeout;
		}

		public int getSocketTimeout() {
			return socketTimeout;
		}

		public void setSocketTimeout(int socketTimeout) {
			this.socketTimeout = socketTimeout;
		}

		public boolean isStaleConnectionCheckEnabled() {
			return staleConnectionCheckEnabled;
		}

		public void setStaleConnectionCheckEnabled(boolean staleConnectionCheckEnabled) {
			this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
		}
		
	}
	
}
